package com.lagou.mr.speakBean;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class SpeakDurationReducer extends Reducer<Text,SpeakBean,Text,SpeakBean> {

    @Override
    protected void reduce(Text key, Iterable<SpeakBean> values, Reducer<Text, SpeakBean, Text, SpeakBean>.Context context) throws IOException, InterruptedException {
        long self_Duration = 0;
        long third_Duration = 0;
        // 1 遍历所用bean，将其中的自有，第三方时长分别累加
        for (SpeakBean sb : values){
            self_Duration += sb.getSelfDuration();
            third_Duration += sb.getThirdParDuration();
        }
        // 2 封装对象
        SpeakBean speakBean = new SpeakBean(self_Duration, third_Duration);

        // 3 写出
        context.write(key,speakBean);
    }
}
